﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for category
/// </summary>
public class categoryDAL
{
    DataAccess da;

    public categoryDAL()
	{
        da = new DataAccess();
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable getCategories(int parent_id,int language_id,bool status)
    {
        SqlParameter[] param = new SqlParameter[4];
        param[0] = da.AddParameter("category_id", DBNull.Value, SqlDbType.Int, null);
        param[1] = da.AddParameter("parent_id", parent_id, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        param[3] = da.AddParameter("status",status, SqlDbType.Bit, null);
        return da.executeSelect("GET_CATEGORY", param);
    }
    
    public DataTable getCategory(int category_id,int language_id)
    {
        SqlParameter[] param=new SqlParameter[4];
        param[0]=da.AddParameter("category_id",category_id,SqlDbType.Int,null);
        param[1] = da.AddParameter("parent_id", DBNull.Value, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        param[3] = da.AddParameter("status","true", SqlDbType.Bit, null);
        return da.executeSelect("GET_CATEGORY",param);
    }
    public DataTable getDescriptionByCategoryID(int category_id){
         SqlParameter[] param=new SqlParameter[1];
        param[0]=da.AddParameter("category_id",category_id,SqlDbType.Int,null);
        return da.executeSelect("GET_CATEGORY",param);
    }
    public int checkParentCategories(int parent_id, int language_id, bool status)
    {
        SqlParameter[] param = new SqlParameter[4];
        param[0] = da.AddParameter("category_id", DBNull.Value, SqlDbType.Int, null);
        param[1] = da.AddParameter("parent_id", parent_id, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        param[3] = da.AddParameter("status", status, SqlDbType.Bit, null);
        return da.executeScalary("GET_CATEGORY", param);
    }
    public DataTable getCategoryNameByID(int category_id, int language_id,bool status)
    {
        SqlParameter[] param = new SqlParameter[4];
        param[0] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        param[1] = da.AddParameter("parent_id", DBNull.Value, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        param[3] = da.AddParameter("status", status, SqlDbType.Bit, null);
        return da.executeSelect("GET_CATEGORY", param);
    }


    public DataTable getCategoriesByLanguageID(int language_id, bool status)
    {
        SqlParameter[] param = new SqlParameter[4];
        param[0] = da.AddParameter("category_id", DBNull.Value, SqlDbType.Int, null);
        param[1] = da.AddParameter("parent_id", DBNull.Value, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        param[3] = da.AddParameter("status", status, SqlDbType.Bit, null);
        return da.executeSelect("GET_CATEGORY", param);
    }
    public int DeleteCategoryByCategory_id(int category_id)
    {
        SqlParameter[] param = new SqlParameter[7];
        param[0] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        param[1] = da.AddParameter("language_id", DBNull.Value, SqlDbType.Int, null);
        param[2] = da.AddParameter("parent_id", DBNull.Value, SqlDbType.Int, null);
        param[3] = da.AddParameter("name", DBNull.Value, SqlDbType.NVarChar, 30);
        param[4] = da.AddParameter("meta_description", DBNull.Value, SqlDbType.NVarChar, 50);
        param[5] = da.AddParameter("date_added", DBNull.Value, SqlDbType.DateTime, null);
        param[6] = da.AddParameter("status", DBNull.Value, SqlDbType.Bit, null);
        return da.executeUpdate("EDIT_CATEGORY", param);

    }
    public DataTable getCategoriesByParentID(int parent_id)
    {
        SqlParameter[] param = new SqlParameter[4];
        param[0] = da.AddParameter("category_id", DBNull.Value, SqlDbType.Int, null);
        param[1] = da.AddParameter("parent_id", parent_id, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", DBNull.Value, SqlDbType.Int, null);
        param[3] = da.AddParameter("status", DBNull.Value, SqlDbType.Bit, null);
        return da.executeSelect("GET_CATEGORY", param);
    }

    public DataTable getAllCategory() {
        return da.executeSelect("GET_CATEGORY");
    }

    public int editCategory(int category_id,int language_id,string name,string description)
    {
        SqlParameter[] param = new SqlParameter[7];
        param[0] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        param[1] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        param[2] = da.AddParameter("parent_id", DBNull.Value, SqlDbType.Int, null);
        param[3] = da.AddParameter("name", name, SqlDbType.NVarChar, 30);
        param[4] = da.AddParameter("meta_description", description, SqlDbType.NVarChar, 50);
        param[5] = da.AddParameter("date_added", DateTime.Now, SqlDbType.DateTime, null);
        param[6] = da.AddParameter("status", DBNull.Value, SqlDbType.Bit, null);
        return da.executeUpdate("EDIT_CATEGORY", param);
    }
    public int editCategoryData(int category_id,int parent_id,bool status,DateTime date_added)
    {
        SqlParameter[] param = new SqlParameter[7];
        param[0] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        param[1] = da.AddParameter("language_id", DBNull.Value, SqlDbType.Int, null);
        param[2] = da.AddParameter("parent_id", parent_id, SqlDbType.Int, null);
        param[3] = da.AddParameter("name", DBNull.Value, SqlDbType.NVarChar, 30);
        param[4] = da.AddParameter("meta_description", DBNull.Value, SqlDbType.NVarChar, 50);
        param[5] = da.AddParameter("date_added", date_added, SqlDbType.DateTime, null);
        param[6] = da.AddParameter("status", status, SqlDbType.Bit, null);
        return da.executeUpdate("EDIT_CATEGORY", param);
    }
    public DataTable getLastCategoryID(int category_id)
    {
        SqlParameter[] param = new SqlParameter[1];
        param[0] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        return da.executeSelect("GET_LASTID", param);
    }
    public DataTable getCategoryEntity(int category_id,bool status)
    {
        SqlParameter[] param = new SqlParameter[4];
        param[0] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        param[1] = da.AddParameter("parent_id", DBNull.Value, SqlDbType.Int, null);
        param[2] = da.AddParameter("language_id", DBNull.Value, SqlDbType.Int, null);
        param[3] = da.AddParameter("status", status, SqlDbType.Bit, null);
        return da.executeSelect("GET_CATEGORY", param);
    }


    
}